<template>
    <div class="resumeform">
        <div class="jibenmsg" v-if="$route.query.msg==1">
            <van-nav-bar title="基本信息" left-text="" fixed placeholder @click-right="savejibenMsg" left-arrow @click-left="$router.back()">
                <template #right>
                    <span>保存</span>
                </template>
            </van-nav-bar>
            <div class="content">
                <van-cell-group>
                    <label for="upload">
                        <div class="content-item">
                            <span>形象照</span>
                            <img v-if="xxzhaopin==''" src="../../assets/images/resume/xingxiangzhao.png" alt="">
                            <img v-else :src="xxzhaopin" alt="">
                            <input
                                id="upload"
                                style="display: none"
                                type="file"
                                accept="image/*"
                                @change="uplodadgongzonghao"
                                class="abc"
                            />
                        </div>
                    </label>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>姓名</span>
                        <br>
                        <van-field v-model="jbform.name" clickable placeholder="请输入姓名">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>性别</span>
                        <van-field v-model="jbform.sex" readonly clickable is-link  placeholder="请选择性别" @click="show1 = true">
                        </van-field>
                        <van-popup v-model="show1" position="bottom">
                            <van-picker title="选择性别" show-toolbar :columns="columns" @cancel="show1 = false" @confirm="onConfirm" />
                        </van-popup>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>手机号</span>
                        <van-field v-model="jbform.phone" type="number" clickable  placeholder="请输入手机号">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                   <div class="contents-item">
                        <span>参加工作时间</span>
                        <van-field v-model="jbform.gztime" is-link readonly @click="show2 = true" placeholder="选择参加工作时间">
                        </van-field>
                        <van-popup v-model="show2" position="bottom">
                            <van-datetime-picker type="year-month" title="选择年月日" @confirm="setGzTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show2 = false" />
                        </van-popup>
                   </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                   <div class="contents-item">
                        <span>出生年月</span>
                        <van-field v-model="jbform.cstime" is-link readonly @click="show3 = true" placeholder="选择出生年月">
                        </van-field>
                        <van-popup v-model="show3" position="bottom">
                            <van-datetime-picker type="date" title="选择年月日" @confirm="setCsTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show3 = false" />
                        </van-popup>
                   </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>邮箱</span>
                        <van-field v-model="jbform.email" clickable  placeholder="请输入邮箱(选填)">
                        </van-field>
                    </div>
                </van-cell-group>
            </div>
        </div>
        <div class="jiaoyubeijing" v-if="$route.query.msg==2">
            <van-nav-bar title="添加教育经历" left-text="" @click-right="savejiaoyuBeijing" fixed placeholder left-arrow @click-left="$publicObj.getReturn">
                <template #right>
                    <span>保存</span>
                </template>
            </van-nav-bar>
            <div class="content">
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>学校</span>
                        <van-field v-model="jiaoyuform.school" clickable placeholder="请输入"></van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>专业</span>
                        <van-field v-model="jiaoyuform.major" clickable placeholder="请输入"></van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>是否全日制</span>
                       <van-field v-model="jiaoyuform.fullTime" readonly clickable is-link placeholder="点击选择" @click="show4 = true">
                        </van-field>
                        <van-popup v-model="show4" position="bottom">
                            <van-picker title="是否全日制" show-toolbar :columns="columnsisFullTime" @cancel="show4 = false" @confirm="onConfirmIsFullTime" />
                        </van-popup>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>开始时间</span>
                       <van-field v-model="jiaoyuform.startTime" readonly clickable is-link placeholder="点击选择" @click="show5 = true">
                        </van-field>
                        <van-popup v-model="show5" position="bottom">
                           <van-datetime-picker type="date" title="选择年月日" @confirm="choosestartTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show5 = false" />
                        </van-popup>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>结束时间</span>
                       <van-field v-model="jiaoyuform.endTime" readonly clickable is-link placeholder="点击选择" @click="show6 = true">
                        </van-field>
                        <van-popup v-model="show6" position="bottom">
                           <van-datetime-picker type="date" title="选择年月日" @confirm="chooseendTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show6 = false" />
                        </van-popup>
                    </div>
                </van-cell-group>
            </div>
        </div>
        <div class="gongzuojingli" v-if="$route.query.msg==3">
             <van-nav-bar title="添加工作经历" @click-right="savegongzuojingli" left-text="" fixed placeholder left-arrow @click-left="$publicObj.getReturn">
                <template #right>
                    <span>保存</span>
                </template>
            </van-nav-bar>
            <div class="content">
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>就职企业</span>
                        <van-field v-model="gongzuoform.enterprise" clickable placeholder="请输入"></van-field>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>在职开始时间</span>
                       <van-field v-model="gongzuoform.startTime" readonly clickable is-link placeholder="点击选择" @click="show7 = true">
                        </van-field>
                        <van-popup v-model="show7" position="bottom">
                           <van-datetime-picker type="date" title="选择年月日" @confirm="chooseZzstartTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show7 = false" />
                        </van-popup>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>在职结束时间</span>
                       <van-field v-model="gongzuoform.endTime" readonly clickable is-link placeholder="点击选择" @click="show8 = true">
                        </van-field>
                        <van-popup v-model="show8" position="bottom">
                           <van-datetime-picker type="date" title="选择年月日" @confirm="chooseZzendTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show8= false" />
                        </van-popup>
                    </div>
                </van-cell-group>
                  <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>上级名称</span>
                        <van-field v-model="gongzuoform.lastname" clickable placeholder="请输入"></van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>上级手机号</span>
                       <van-field v-model="gongzuoform.lastphone" type="number" clickable placeholder="点击输入">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:180px">
                    <div class="contents-item">
                        <span>离职原因</span>
                        <van-field v-model="gongzuoform.resignationReason" rows="4" autosize type="textarea" maxlength="150" placeholder="点击输入" show-word-limit>
                        </van-field>
                    </div>
                </van-cell-group>
            </div>
        </div>
        <div class="ziwopingjia" v-if="$route.query.msg==4">
            <van-nav-bar title="自我评价" left-text="" @click-right="saveziwopingjia" fixed placeholder left-arrow @click-left="$publicObj.getReturn">
                <template #right>
                    <span>保存</span>
                </template>
            </van-nav-bar>
            <div class="content">
                <van-cell-group style="height:230px">
                    <div class="contents-item">
                        <van-field v-model="ziwopingjia" rows="8" autosize type="textarea" maxlength="150" placeholder="一句话介绍一下自己" show-word-limit>
                        </van-field>
                    </div>
                </van-cell-group>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            show1:false,
            show2:false,
            show3:false,
            show4:false,
            show5:false,
            show6:false,
            show7:false,
            show8:false,
            xxzhaopin:"",
            minDate: new Date(1980, 0, 1),
            maxDate: new Date(2025, 10, 1),
            columns:["男","女"],
            columnsisFullTime:["是","否"],
            ziwopingjia:"",
            jbform:{
                sex:"",
                name:"",
                phone:"",
                gztime:"",
                cstime:"",
                email:"",
            },
            jiaoyuform:{
                school:"",
                major:"",
                fullTime:"",
                startTime:"",
                endTime:""
            },
            gongzuoform:{
                enterprise:"",
                startTime:"",
                endTime:"",
                lastname:"",
                lastphone:"",
                resignationReason:""
            }
        }
    },
    mounted(){
        if(this.$route.query.id){
            this.getPersonalResumeInfo(this.$route.query.id)
            if(this.$route.query.jiaoyuid){
                this.getPersonalResumeInfo1(this.$route.query.jiaoyuid)
            }
            if(this.$route.query.gongzuoid){
                this.getPersonalResumeInfo2(this.$route.query.gongzuoid)
            }
            if(this.$route.query.remark){
                this.ziwopingjia=this.$route.query.remark
            }
        }
    },
    methods:{
       getPersonalResumeInfo(id){
           this.$api.getPersonalResumeInfo({id:id,tableId:4}).then(res=>{
               this.jbform.name=res.data.name
               this.xxzhaopin=res.data.cover
               this.jbform.sex=res.data.gender
               this.jbform.phone=res.data.phone
               this.jbform.gztime=res.data.workTime
               this.jbform.cstime=res.data.birth
               this.jbform.email=res.data.email
           })
       },
       getPersonalResumeInfo1(id){
           this.$api.getPersonalResumeInfo({id:id,tableId:2}).then(res=>{
               this.jiaoyuform=res.data
           })
       },
       getPersonalResumeInfo2(id){
           this.$api.getPersonalResumeInfo({id:id,tableId:3}).then(res=>{
               this.gongzuoform.enterprise=res.data.companyName
               this.gongzuoform.startTime=res.data.startTime
               this.gongzuoform.endTime=res.data.endTime
               this.gongzuoform.lastname=res.data.superiorName
               this.gongzuoform.lastphone=res.data.superiorPhone
               this.gongzuoform.resignationReason=res.data.resignationReason
           })
       },
        uplodadgongzonghao(e) {
            const file = e.target.files[0] || e.dataTransfer.files[0];
            this.afterReads(file);
        },
        afterReads(files) {
        let _this = this;
        //判断是否为图片文件
        if (files.type.indexOf("image") == -1) {
            this.$toast("请上传图片文件");
        } else {
            this.$publicObj.getLoading();
            _this.$publicObj.uploadFile(
            files,
            function (imgData) {
                _this.xxzhaopin = imgData;
                _this.$toast("上传成功");
                _this.$publicObj.closeLoading();
            },
            "/sys/oss/upload"
            );
        }
        },
        // 基本信息保存
        savejibenMsg(){
            if(this.jbform.email!=="" && this.jbform.email!==undefined){
                let myreg=/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
                if(!myreg.test(this.jbform.email)){
                    this.$toast("邮箱格式不正确")
                    return;
                }
            }
            // 手机号正则
            let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if(this.xxzhaopin==""){
                this.$toast("请上传你的形象照");
                return;
            }
            if(this.jbform.name==""){
                this.$toast("请输入姓名");
                return;
            }else if(this.jbform.sex==""){
                this.$toast("请选择性别");
                return;
            }else if(this.jbform.phone==""){
                this.$toast("请输入手机号");
                return;
            }else if(!myreg.test(this.jbform.phone)){
                this.$toast("手机号格式不正确")
                return;
            }else if(this.jbform.gztime==""){
                this.$toast("请输入参加工作时间");
                return;
            }else if(this.jbform.cstime==""){
                this.$toast("请选择出生年月");
                return;
            }
            let obj={
                id:this.$route.query.id,
                type:2,
                customerId:sessionStorage.getItem("agentIds"),
                cover:this.xxzhaopin,
                name:this.jbform.name,
                gender:this.jbform.sex,
                phone:this.jbform.phone,
                workTime:this.jbform.gztime,
                birth:this.jbform.cstime,
                email:this.jbform.email
            }
            this.$api.addRecruitTalent(obj).then(res=>{
                if(res.code==0){
                    this.$toast("操作成功")
                   this.$router.push({path:"/resume",query:{id:this.$route.query.recruitId}})
                }else{
                    this.$toast("操作失败")
                }
            })
        },
        // 教育背景保存
        savejiaoyuBeijing(){
            if(this.jiaoyuform.school==""){
                this.$toast("请输入你的学校名称");
                return;
            }else if(this.jiaoyuform.major==""){
                this.$toast("请输入你的专业");
                return;
            }else if(this.jiaoyuform.fullTime==""){
                this.$toast("请选择是否全日制");
                return;
            }else if(this.jiaoyuform.startTime==""){
                this.$toast("请选择开始时间");
                return;
            }else if(this.jiaoyuform.endTime==""){
                this.$toast("请选择结束时间");
                return;
            }else if(new Date(this.jiaoyuform.endTime).getTime()-new Date(this.jiaoyuform.startTime).getTime()<0){
                this.$toast("结束时间不能小于开始时间")
                return
            }else{
              if(this.$route.query.jiaoyuid){
                let obj={
                    id:this.$route.query.jiaoyuid,
                    school:this.jiaoyuform.school,
                    major:this.jiaoyuform.major,
                    fullTime:this.jiaoyuform.fullTime,
                    startTime:this.jiaoyuform.startTime,
                    endTime:this.jiaoyuform.endTime
                }
                var crmPersonnelEducationEntity=[];
                crmPersonnelEducationEntity.push(obj)
                this.$api.addRecruitTalent({id:this.$route.query.id,crmPersonnelEducationEntity:crmPersonnelEducationEntity}).then(res=>{
                    if(res.code==0){
                        this.$toast("修改成功")
                        this.$router.push(`/briefonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                    }else{
                        this.$toast("修改失败")
                    }
                })
            }else{
                let obj={
                    school:this.jiaoyuform.school,
                    major:this.jiaoyuform.major,
                    fullTime:this.jiaoyuform.fullTime,
                    startTime:this.jiaoyuform.startTime,
                    endTime:this.jiaoyuform.endTime
                }
                var crmPersonnelEducationEntity=[];
                crmPersonnelEducationEntity.push(obj)
                this.$api.addRecruitTalent({id:this.$route.query.id,crmPersonnelEducationEntity:crmPersonnelEducationEntity}).then(res=>{
                    if(res.code==0){
                        this.$toast("添加成功")
                        this.$router.push(`/briefonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                    }else{
                        this.$toast("添加失败")
                    }
                })
            }
          }

        },
        // 工作经历
        savegongzuojingli(){
               // 手机号正则
            let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
             if(this.gongzuoform.enterprise==""){
                this.$toast("请输入就在企业");
                return;
            }else if(this.gongzuoform.startTime==""){
                this.$toast("请选择开始时间");
                return;
            }else if(this.gongzuoform.endTime==""){
                this.$toast("请选择结束时间");
                return;
            }else if(new Date(this.gongzuoform.endTime).getTime()-new Date(this.gongzuoform.startTime).getTime()<=0){
                this.$toast("结束时间不能小于开始时间")
                return
            }else if(this.gongzuoform.lastname==""){
                this.$toast("请输入上级姓名");
                return;
            }else if(this.gongzuoform.lastphone==""){
                this.$toast("请输入上级手机号");
                return;
            }else if(!myreg.test(this.gongzuoform.lastphone)){
                this.$toast("手机号格式不正确")
                return;
            }else if(this.gongzuoform.resignationReason==""){
                this.$toast("请输入离职原因");
                return;
            }else{
              if(this.$route.query.gongzuoid){
                   let obj={
                        id:this.$route.query.gongzuoid,
                        startTime:this.gongzuoform.startTime,
                        endTime:this.gongzuoform.endTime,
                        companyName:this.gongzuoform.enterprise,
                        superiorName:this.gongzuoform.lastname,
                        superiorPhone:this.gongzuoform.lastphone,
                        resignationReason:this.gongzuoform.resignationReason
                    }
                    var crmWorkExperienceEntity=[];
                    crmWorkExperienceEntity.push(obj)
                    this.$api.addRecruitTalent({id:this.$route.query.id,crmWorkExperienceEntity:crmWorkExperienceEntity}).then(res=>{
                        if(res.code==0){
                            this.$toast("修改成功")
                            this.$router.push(`/briefonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                        }else{
                            this.$toast("修改失败")
                        }
                    })
                }else{
                    let obj={
                        startTime:this.gongzuoform.startTime,
                        endTime:this.gongzuoform.endTime,
                        companyName:this.gongzuoform.enterprise,
                        superiorName:this.gongzuoform.lastname,
                        superiorPhone:this.gongzuoform.lastphone,
                        resignationReason:this.gongzuoform.resignationReason
                    }
                    var crmWorkExperienceEntity=[];
                    crmWorkExperienceEntity.push(obj)
                    this.$api.addRecruitTalent({id:this.$route.query.id,crmWorkExperienceEntity:crmWorkExperienceEntity}).then(res=>{
                        if(res.code==0){
                            this.$toast("添加成功")
                            this.$router.push(`/briefonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                        }else{
                            this.$toast("添加失败")
                        }
                    })
                }
            }
        },
        saveziwopingjia(){
             if(this.ziwopingjia==""){
                this.$toast("请输入自我评价");
                return;
            }
            this.$api.addRecruitTalent({id:this.$route.query.id,remark:this.ziwopingjia}).then(res=>{
                if(res.code==0){
                    this.$toast("操作成功")
                     this.$router.push(`/briefonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                }else{
                    this.$toast("操作失败")
                }
            })
            
        },
        // 处理时间的方法
        disposeDate (now) {
            var year = now.getFullYear(); //年
            var month = now.getMonth() + 1; //月
            var day = now.getDate(); //日
            if (String(month).length != 2) {
                month = 0 + String(month);
            }
            if (String(day).length != 2) {
                day = 0 + String(day);
            }
            return `${year}-${month}-${day}`;
        },
            // 处理时间的方法
        disposeDates (now) {
            var year = now.getFullYear(); //年
            var month = now.getMonth() + 1; //月
            if (String(month).length != 2) {
                month = 0 + String(month);
            }
            return `${year}-${month}`;
        },
        //性别
        onConfirm (value) {
            this.jbform.sex = value
            this.show1 = false
        },
        // 是否全日制
        onConfirmIsFullTime (value) {
            this.jiaoyuform.fullTime=value
            this.show4 = false
        },
        // 参加工作年限
        setGzTime (time) {
            this.jbform.gztime = this.disposeDates(new Date(time))
            this.show2 = false;
        },
        // 开始时间
        choosestartTime(time){
            this.jiaoyuform.startTime = this.disposeDate(new Date(time))
            this.show5 = false;
        },
        // 在职开始时间
        chooseZzstartTime(time){
            this.gongzuoform.startTime = this.disposeDate(new Date(time))
            this.show7 = false;
        },
        // 结束时间
        chooseendTime(time){
            this.jiaoyuform.endTime = this.disposeDate(new Date(time))
            this.show6 = false;
        },
        // 在职结束时间
        chooseZzendTime(time){
            this.gongzuoform.endTime = this.disposeDate(new Date(time))
            this.show8 = false;
        },
        // 出生年月
        setCsTime (time) {
            this.jbform.cstime = this.disposeDate(new Date(time))
            this.show3 = false;
        },
    }
}
</script>
<style lang="less" scoped>
.jibenmsg{
    .content{
        margin: 0 auto;
        .content-item{
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            padding: 10px;
            span{
                display: block;
                margin-top: 0.7rem;
                padding-left: 15px;
            }
            img{
                width: 45px;
                height: 45px;
                border-radius: 2em;
            }
        }
        .contents-item{
            padding: 10px;
            line-height: 20px;
            span{
                padding-left: 15px;
            }
        }
    }
}
.jiaoyubeijing{
    .content{
        margin: 0 auto;
        .content-item{
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            padding: 10px;
            span{
                display: block;
                margin-top: 0.7rem;
                padding-left: 15px;
            }
            img{
                width: 45px;
                height: 45px;
                border-radius: 2em;
            }
        }
        .contents-item{
            padding: 10px;
            line-height: 20px;
            span{
                padding-left: 15px;
            }
        }
    }
}
.gongzuojingli{
    .content{
        margin: 0 auto;
        .content-item{
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            padding: 10px;
            span{
                display: block;
                margin-top: 0.7rem;
                padding-left: 15px;
            }
            img{
                width: 45px;
                height: 45px;
                border-radius: 2em;
            }
        }
        .contents-item{
            padding: 10px;
            line-height: 20px;
            span{
                padding-left: 15px;
            }
        }
    }
}
</style>